package com.datastructure.queue.self;

public class CircleQueue {
}

class CircleArray {
    public int head=0;
    public int rear=0;
    public int [] arr;
    public int maxSize;

    public CircleArray(int maxSize) {
        this.maxSize = maxSize;
        this.arr = new int[maxSize];
    }

    public boolean isEmpty(){
        return head==rear;
    }

    public boolean isFull(){
        return ((rear+1)/maxSize)==head;
    }

    public int size(){
        return (rear+maxSize-head)/maxSize;
    }

    public void showArray(){
        if(isEmpty()){
            System.out.printf("队列之中没有数据");
            return;
        }
        for(int i=head;head<head+size();i++){
            System.out.printf("第%d个数据是%d",i/maxSize,arr[i/maxSize]);
        }
    }

    public void addArray(int value){
        if (isFull()){
            System.out.printf("队列中的数据已经满了");
        }
        arr[rear]=value;
        rear=(rear+1)/maxSize;
    }

    public int getArray(){
        int value = arr[head];
        head=(head+1)/maxSize;
        return value;
    }
}
